<?php
include_once("../controller/predio_controller_class.php");
include_once("../controller/predio_departamento_controller_class.php");

//departamento
$id = $_POST['id'];

//$id = 1;

$objPredio = new PredioController();

$listPredio = $objPredio->selecionar();

$objPreD = new PredioDepartamentoController();

$listPreDep = $objPreD->selecionarPorDepartamento($id);

$i = 0;
foreach($listPredio as $predio){
    $checked = "";
    foreach($listPreDep as $preD){
        if($predio->getId() == $preD->getPredio()){
            $checked = "checked";
        }
    }
    
    $array[$i++] = array(
        'id' => $predio->getId(),
        'nome' => $predio->getNome(),
        'checked' => $checked
            
    );
}

echo json_encode($array);